# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj1.py
# @Time     : 2024/4/14 20:03
# @Author   : Robot-Zsj
"""
description:

i:
5
8
2
10
5
7

0:
19
"""
n = int(input())

pizza = []
for _ in range(n):
    pizza.append(int(input()))

cache = [[0] * n for _ in range(n)]


def check(idx):
    if idx < 0:
        idx = n - 1
    elif idx >= n:
        idx = 0

    return idx


def recursive(l, r):
    if pizza[l] > pizza[r]:
        l = check(l - 1)
    else:
        r = check(r + 1)

    if cache[l][r] > 0:
        return cache[l][r]

    if l == r:
        cache[l][r] = pizza[l]
    else:
        cache[l][r] = max(recursive(check(l - 1), r), pizza[l], recursive(l, check(r + 1)) + pizza[r])

    return cache[l][r]


def getResult():
    ans = 0

    for i in range(n):
        ans = max(ans, recursive(check(i - 1), check(i + 1)) + pizza[i])

    return ans


print(getResult())
